package org.liquidByte.trafficMustang.androidApp.dialogs;

import org.liquidByte.trafficMustang.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;

public class RatingDialog extends Dialog implements OnClickListener {

	private Button btnOk;
	private EditText editText;
	private RatingBar ratingBar;
	
	private float rating;
	private String descricao;
	
	public RatingDialog(Context context) {
		super(context);
		this.setContentView(R.layout.dialog_rating);
	}
	public RatingDialog(Context context, int theme) {
		super(context, theme);
		this.setContentView(R.layout.dialog_rating);
	}
	
	protected Button getBtnOk() {
		if (this.btnOk == null) {
			this.btnOk = (Button)this.findViewById(R.id.dialog_rating_ok);
		}
		return btnOk;
	}
	
	protected EditText getEditText() {
		if (this.editText == null) {
			this.editText = (EditText)this.findViewById(R.id.dialog_rating_edittext);
		}
		return editText;
	}
	
	protected RatingBar getRatingBar() {
		if (this.ratingBar == null) {
			this.ratingBar = (RatingBar)this.findViewById(R.id.dialog_rating_ratingBar);
		}
		return ratingBar;
	}

	public float getRating() {
		return rating;
	}
	
	public void setRating(float rating) {
		this.rating = rating;
	}
	
	public String getDescricao() {
		return descricao;
	}
	
	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		this.getBtnOk().setOnClickListener(this);
		
		this.getEditText().setText(this.getDescricao());
		this.getRatingBar().setRating(this.getRating());
	}

	@Override
	public void onClick(View v) {
		if (this.getBtnOk() == v) {
			this.setDescricao(this.getEditText().getText().toString());
			this.setRating(this.getRatingBar().getRating());
			
			this.dismiss();	
		}
	}
}
